allocate temporary buffers for fish conversion on the stack
authorØyvind Kolås <pippin@gimp.org>
Sun, 22 Apr 2012 23:07:14 +0000 (01:07 +0200)
committerØyvind Kolås <pippin@gimp.org>
Sun, 22 Apr 2012 23:09:06 +0000 (01:09 +0200)
This avoids calling malloc/free for fishes that consists of multiple steps.

babl/babl-fish-path.c

index 7914e0c84162a9e8466d20161c2be1803ceadc76..f51501e651112621b50b2da91e6bc4a300a99f3c 100644 (file)
@@ -410,6 +410,16 @@ babl_process (const Babl *cbabl,
   return -1;
 }
 
+#include <stdint.h>
+
+#define BABL_ALIGN 16
+static void inline *align_16 (unsigned char *ret)
+{
+  int offset = BABL_ALIGN - ((uintptr_t) ret) % BABL_ALIGN;
+  ret = ret + offset;
+  return ret;
+}
+
 static long
 process_conversion_path (BablList   *path,
                          const void *source_buffer,
@@ -427,7 +437,7 @@ process_conversion_path (BablList   *path,
     }
   else
     {
-      void *aux1_buffer = babl_malloc (n * sizeof (double) * 5);
+      void *aux1_buffer = align_16 (alloca (n * sizeof (double) * 5 + 16));
       void *aux2_buffer = NULL;
       void *swap_buffer = NULL;
       int   i;
@@ -435,7 +445,7 @@ process_conversion_path (BablList   *path,
       if (conversions > 2)
         {
           /* We'll need one more auxiliary buffer */
-          aux2_buffer = babl_malloc (n * sizeof (double) * 5);
+          aux2_buffer = align_16 (alloca ((n * sizeof (double) * 5 + 16)));
         }
 
       /* The first conversion goes from source_buffer to aux1_buffer */
@@ -463,12 +473,6 @@ process_conversion_path (BablList   *path,
                                aux1_buffer,
                                destination_buffer,
                                n);
-
-      /* Free auxiliary buffers */
-      if (aux1_buffer)
-        babl_free (aux1_buffer);
-      if (aux2_buffer)
-        babl_free (aux2_buffer);
   }
 
   return n;